package player

import (
	"github.com/name5566/leaf/log"
	"go.mongodb.org/mongo-driver/bson"
	db2 "server/db"
	"server/game/player/db"
)

// 模拟从数据库获取玩家信息的函数
func getPlayerFromDatabase(uid string, key string) (db.Player, error) {
	// 这里可以根据 UID 从数据库查询玩家信息，例如使用 MongoDB 或 MySQL
	// 以下是一个简单的示例，返回一个空的 Player 结构体
	var player db.Player
	err := db2.Db.FindOne(db.USERTABLENAME, bson.M{key: uid}, &player)
	return player, err
}
func GetUserZhuanSun(uid string) int32 {
	return 100
}

func getUserInfo(uid string) (map[string]interface{}, error) {
	var ret = make(map[string]interface{}, 0)
	playerCheck, err := getPlayerFromDatabase(uid, "uid")
	if err != nil {
		return ret, err
	}
	//playerCheck.
	ret["player_info"] = playerCheck
	return ret, nil
}

func UpdateXuanChuanTilI(userId string, chuanTiLI int) error {
	err := db2.Db.Update(db.USERTABLENAME, bson.M{"uid": userId}, map[string]interface{}{
		"$set": map[string]interface{}{"xuan_chuan_ti_li": chuanTiLI},
	})
	if err != nil {
		log.Error("error msg is %v", err)
		return err
	}
	return nil
}
func JoinUnion(userId string, unionId int32) error {
	err := db2.Db.Update(db.USERTABLENAME, bson.M{"uid": userId}, map[string]interface{}{
		"$set": map[string]interface{}{"union_id": unionId},
	})
	if err != nil {
		log.Error("error msg is %v", err)
		return err
	}
	return nil
}
